package com.note7_11.question1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Question1_Click {

	public static void main(String[] args) {
		Socket s = null;
		try {
			s = new Socket("127.0.0.1",8090);
			OutputStream out = s.getOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(out);
			Scanner in = new Scanner(System.in);
			System.out.println("请输入用户名：");
			String name = in.next();
			System.out.println("请输入密码：");
			String pw = in.next();
			User user = new User(name,pw);
			oos.writeObject(user);
			InputStream is = s.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String str = br.readLine();
			if(str.equals("quit")){
				System.out.println("用户名与密码不匹配，请重试！");
			}else{
				System.out.println(str);
			}
			oos.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(s != null){
				try {
					s.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
